// src/main/java/com/ruoyi/web/controller/order/OrderCommentController.java
package com.ruoyi.web.order;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.order.domain.OrderCommentDTO;

import com.ruoyi.system.order.domain.OrderCommentQueryDTO;
import com.ruoyi.system.order.service.OrderCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/reviews")
public class OrderCommentController extends BaseController {

    @Autowired
    private OrderCommentService orderCommentService;

    /**
     * 分页列表
     * GET /order/comment/list?pageNum=1&pageSize=10&orderNo=...
     */
    @Anonymous
    @GetMapping("/list")
    public TableDataInfo list(OrderCommentQueryDTO q) {
        /* a. 解析时间区间 */
        q.resolveTimeRange();

        /* b. star → rating 条件在 XML 直接用 q.star */
        List<OrderCommentDTO> list = orderCommentService.page(q);
        return getDataTable(list);
    }

    /**
     * 不分页导出 / 全量查询
     */
    @Anonymous
    @GetMapping("/all")
    public AjaxResult all(OrderCommentQueryDTO q) {
        // 把 pageSize 设一个极大值，或者直接不调用 PageHelper
        q.setPageNum(1);
        q.setPageSize(Integer.MAX_VALUE);
        return AjaxResult.success(orderCommentService.page(q));
    }

    @Anonymous
    @GetMapping("/getOne")
    public AjaxResult getOne(Long id){
        return AjaxResult.success(orderCommentService.getOne(id));
    }
}
